package com.example.yuejianapp14.Activity.Model;

import com.example.yuejianapp14.Activity.JavaBean.Act;
import com.example.yuejianapp14.Activity.Listener.ActListener;
import com.example.yuejianapp14.Activity.Listener.ClubNoListListener;
import com.example.yuejianapp14.Activity.Servics.ActService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 张森 on 2017/9/25.
 */

public class ActivityModel {

    private Retrofit retrofit;
    private String BASEURL ="http://10.0.2.2/YueJian/index.php/Api/Activity/";
    private String HeadPhotoNameDefault="user_headphoto.png";

    public ActivityModel(){
        retrofit= new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }




    public void getActList(final ActListener listener){
        ActService actServic=retrofit.create(ActService.class);
        Call<List<Act>> call=actServic.getAct();
        call.enqueue(new Callback<List<Act>>() {
            @Override
            public void onResponse(Call<List<Act>> call, Response<List<Act>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }
            @Override
            public void onFailure(Call<List<Act>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });


    }

    public void actinfo (String actid,final ClubNoListListener listener){
        ActService actServic=retrofit.create(ActService.class);
        Call call = actServic.actinfo(actid);
        Callback<Act> callback =new Callback<Act>() {
            @Override
            public void onResponse(Call<Act> call, Response<Act> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                }else
                    listener.onFail("onresponse fail");

            }

            @Override
            public void onFailure(Call<Act> call, Throwable t) {

            }
        };
        call.enqueue(callback);
    }


}
